package org.healer.simple_juc;

import org.apache.commons.io.FileUtils;
import org.xml.sax.ext.Attributes2;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread{
    private String url;
    private String name;

    public TestThread2(String url,String name){
        this.url=url;
        this.name=name;
    }
    @Override
    public void run() {
        WebDownloader wd=new WebDownloader();
        wd.Downloader(url,name);
        System.out.println("下载了文件"+name);

    }

    public static void main(String[] args) {
        TestThread2 t1=new TestThread2("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnews.yunnan.cn%2Fpic%2F003%2F038%2F125%2F00303812512_6f4574f3.jpg&refer=http%3A%2F%2Fnews.yunnan.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=b89b5d6a5a90166d8a53dae85f65bbf5","袁隆平1.jpg");
        TestThread2 t2=new TestThread2("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgpolitics.gmw.cn%2Fattachement%2Fjpg%2Fsite2%2F20210522%2Ff44d305ea0d8221328f424.jpg&refer=http%3A%2F%2Fimgpolitics.gmw.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=33b7888d21ff885c6c9a6acdc9906ff6","袁隆平2.jpg");
        TestThread2 t3=new TestThread2("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgpolitics.gmw.cn%2Fattachement%2Fjpg%2Fsite2%2F20210522%2Ff44d305ea0d82213299150.jpg&refer=http%3A%2F%2Fimgpolitics.gmw.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=2a46222fb05b2c036b8240b957fae89c","袁隆平3.jpg");
        t1.start();
        t2.start();
        t3.start();
    }
}
//下载器
class WebDownloader{
    //下载方法
    public void Downloader(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}